﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sustainalytics.CDDB.DataConnector;
using Sustainalytics.Entities;
using Sustainalytics.Synchronization.Interface;

namespace Sustainalytics.Governance.Synchronization
{
    public class CorporateDataQuery
    {
        private readonly CorporateDataRepository _corporateDataRepository;
        private readonly BackOfficeAppSettings _backOfficeAppSettings;
        private readonly ILogger _logger;

        public CorporateDataQuery(ILogger logger,
            CorporateDataRepository corporateDataRepository,
            BackOfficeAppSettings hBaseAppSettings)
        {
            _logger = logger;
            _corporateDataRepository = corporateDataRepository;
            _backOfficeAppSettings = hBaseAppSettings;
        }

        public IList<T> Get<T>(Func<CorporateDataRepository, IEnumerable<T>> getEntities)
        {
            return Retry.Do(() => getEntities(_corporateDataRepository).ToList(),
                _backOfficeAppSettings.WaitRetryDuration,
                _logger,
                _backOfficeAppSettings.RetryNumberOfTimes);
        }
    }
}
